<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Interlocution extends Model
{
    protected $table = 'interlocution';

    protected $fillable = ['uid',  'body', 'for', 'status'];

    const UPDATED_AT = null;

    public static function Get_List($Id, $for)
    {
        return self::orWhere(function ($query) use ($Id, $for) {
            $query->where('for', $Id)->where('uid', $for);
        })->orWhere(function ($query) use ($Id, $for) {
            $query->where('for', $for)->where('uid', $Id);
        })->select('id', 'body', 'created_at', 'uid')->orderBy('created_at', 'desc')->paginate(10);
    }

    public static function Add($data)
    {
        return self::create($data);
    }

    public static function Get_Info($id)
    {
        return self::where('for', $id)->where('status', 1)->count();
    }

    public static function Clear_Msg($uid, $for)
    {
        return self::where('uid', $uid)->where('status', 1)->where('for', $for)->update(['status' => 0]);
    }

    public function freshTimestamp()
    {
        return time();
    }

    public function fromDateTime($value)
    {
        return $value;
    }

    public function getDateFormat()
    {
        return 'U';
    }
}
